package cn.itcast.service;

import cn.itcast.constant.MessageConstant;
import cn.itcast.entity.Result;
import cn.itcast.pojo.OrderSetting;
import jdk.nashorn.internal.ir.annotations.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Date;

@Service
@Slf4j
public class OrderService {
    @Reference
    private MobileOrderSettingService orderSettingService;

    /**
     * 查询用户预约的日期能否正常预约
     * @param orderDate
     * @return
     */
    public Result queryIsOrder(Date orderDate) {
        // 查询当前有没有预约
        OrderSetting orderSetting = this.orderSettingService.findByOrderDate(orderDate);
        if(ObjectUtils.isEmpty(orderSetting)){
            return new Result(false, MessageConstant.SELECTED_DATE_CANNOT_ORDER,null);
        }

        int reservations = orderSetting.getReservations();
        int number = orderSetting.getNumber();
        int num = number - reservations;
        if(num > 0){
            return new Result(true,MessageConstant.ORDER_SUCCESS);
        }else{
            return new Result(true,MessageConstant.ORDER_FULL,null);
        }
    }
}
